package com.pe1n.yangtaopai.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.pe1n.yangtaopai.R;
import com.pe1n.yangtaopai.bean.ListtwoBean;
import com.pe1n.yangtaopai.view.activity.ItemTwoListActivity;

import java.util.List;

/**
 * Created by Administrator on 2016/11/23.
 */

public class MyAmountItemRecyclerAdapter extends RecyclerView.Adapter<MyAmountItemRecyclerAdapter.MyViewItemHolder> {
    private Context mContext;
    private List<ListtwoBean.DataBean> listtwoBeen;

    public MyAmountItemRecyclerAdapter(Context mContext, List<ListtwoBean.DataBean> listtwoBeen) {
        this.mContext = mContext;
        this.listtwoBeen = listtwoBeen;
    }


    @Override
    public MyViewItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_listtwo_image_layout, parent, false);
        return new MyViewItemHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewItemHolder holder, final int position) {
        ListtwoBean.DataBean bean = listtwoBeen.get(position);
        final String imgUrl = bean.getImagePath();
        Glide.with(mContext)
                .load(imgUrl)
                .placeholder(R.drawable.place_holder)
                .into(holder.item_listtwo_imageview);
        holder.item_listtwo_textview.setText(bean.getTitle());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, ItemTwoListActivity.class);
                String name = listtwoBeen.get(position).getTitle();
                String id = listtwoBeen.get(position).getTargetId();
                intent.putExtra("name", name);
                intent.putExtra("id", id);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return listtwoBeen.size();
    }

    class MyViewItemHolder extends RecyclerView.ViewHolder {
        private LinearLayout item_listtwo_linearlayout;
        private ImageView item_listtwo_imageview;
        private TextView item_listtwo_textview;

        public MyViewItemHolder(View itemView) {
            super(itemView);
            item_listtwo_imageview = (ImageView) itemView.findViewById(R.id.item_listtwo_image);
            item_listtwo_textview = (TextView) itemView.findViewById(R.id.item_listtwo_textview);
            item_listtwo_linearlayout = (LinearLayout) itemView.findViewById(R.id.item_listtwo_Lineatlayout);

        }
    }
}
